<?php

/**
 * testsuite actions.
 *
 * @package    tectesu
 * @subpackage testsuite
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class testsuiteActions extends sfActions
{
	
  public function  executeListTestSuiteById(sfWebRequest $request){
    $this->id =  $request->getParameter('id');
    if (!$this->id)
    {
      $this->id = $this->getUser()->getAttribute('IdUser');
    }
    
    $this->testSuite = new Testsuite();
    $this->testsuite_list = $this->testSuite->getListTestSuiteById($this->id);
  }	
  
  public function executeIndex(sfWebRequest $request)
  {
    $this->testsuite_list = Doctrine::getTable('Testsuite')
      ->createQuery('a')
      ->execute();
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new TestsuiteForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new TestsuiteForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($testsuite = Doctrine::getTable('Testsuite')->find(array($request->getParameter('id'))), sprintf('Object testsuite does not exist (%s).', array($request->getParameter('id'))));
    $this->form = new TestsuiteForm($testsuite);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($testsuite = Doctrine::getTable('Testsuite')->find(array($request->getParameter('id'))), sprintf('Object testsuite does not exist (%s).', array($request->getParameter('id'))));
    $this->form = new TestsuiteForm($testsuite);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($testsuite = Doctrine::getTable('Testsuite')->find(array($request->getParameter('id'))), sprintf('Object testsuite does not exist (%s).', array($request->getParameter('id'))));
    $testsuite->delete();

    $this->redirect('testsuite/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()));
    if ($form->isValid())
    {
      $testsuite = $form->save();

      $this->redirect('testsuite/edit?id='.$testsuite['id']);
    }
  }
}
